/**********************************************************
 *
 *  Copyright (c) 2003  SeikoEpson Inc
 *  All Rights Reserved
 *
 *  File name : f_ceil.c
 *  Function  :
 *        f_ceil function returns a value whose fraction part
 *                  is changed to 1, if the fraction part is not 0.
 *        This file is copied from math.lib of 
 *                  CC33 tool(CC33v40.exe + CCPA45.exe, 
 *                  math of ansilib33v25 )
 *  original file's Revision  :
 *      2000/02/10    first release                 M.Igarashi
 *  Revision  :
 *      2003/04/10    IrumaSoft M.Takeishi   1.st design
 *
 **********************************************************/

#include	<f_math.h>
#include        <f_smcvals.h>
// ALGORITHM
// 1.ceil(x)=-floor(-x)
//


//
//  the architecture of float floating point
//
//   0 30         23 22                0  32 bit
//   -----------------------------------
//  | |   exponent  |  fraction         |
//   -----------------------------------
//
//  |               |                   |
//  |    8 bits     |    23 bits        |
//
//         bit    31         sign bit        (  1 bit  )
//             30 - 23      exponent part    (  8 bits )
//             22 -  0      fraction part    ( 23 bits )
//
//
//

float f_ceil(float sfX){

	register FLT_LNG sfRet, sfNaN;

	sfRet._F = sfX;
	sfNaN._F = f_NAN._F;
	/* Is NaN? */
	if ( (sfRet.st._LL & sfNaN.st._LL ) == sfNaN.st._LL ) {
		errno = EDOM;
		return sfNaN._F;
	}

	sfRet._F =-f_floor(-sfRet._F );	//calc f_ceil(sfX)= -f_floor(-sfX)
	
	return sfRet._F;
}
